package com.zw.yzk.kabu.view.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.zw.yzk.kabu.R;
import com.zw.yzk.kabu.adapter.GoodsOrderFragmentAdapter;
import com.zw.yzk.kabu.base.BaseActivity;
import com.zw.yzk.kabu.data.network.task.GoodsOrderTask;
import com.zw.yzk.kabu.management.ToolbarBuilder;
import com.zw.yzk.kabu.view.fragment.GoodsOrderFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.Bind;

/**
 * Created by zhanwei on 2017/2/8.
 */

public class MyGoodsOrderActivity extends BaseActivity {

    @Bind(R.id.indicator)
    TabLayout indicator;
    @Bind(R.id.view_pager)
    ViewPager viewPager;

    @Override
    public int getLayoutId() {
        return R.layout.activity_my_goods_order;
    }

    @Override
    public void iniToolbar(BaseActivity activity) {
        ToolbarBuilder
                .createBuilder(this)
                .setTitle(getResources().getString(R.string.my_goods_order))
                .build();
    }

    @Override
    public void initComponent() {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initViewPager();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /**
     * 初始化ViewPager
     */
    private void initViewPager() {
        String[] tab = getResources().getStringArray(R.array.goods_order_title);

        List<GoodsOrderFragment> fragmentList = new ArrayList<>();
        GoodsOrderFragment typeAll = new GoodsOrderFragment();
        typeAll.setOrderType(GoodsOrderTask.GOODS_ORDER_ALL);
        fragmentList.add(typeAll);
        GoodsOrderFragment typeUnpaied = new GoodsOrderFragment();
        typeUnpaied.setOrderType(GoodsOrderTask.GOODS_ORDER_UNPAIED);
        fragmentList.add(typeUnpaied);
        GoodsOrderFragment typeUndelive = new GoodsOrderFragment();
        typeUndelive.setOrderType(GoodsOrderTask.GOODS_ORDER_UNDELIVER);
        fragmentList.add(typeUndelive);
        GoodsOrderFragment typeUnrecived = new GoodsOrderFragment();
        typeUnrecived.setOrderType(GoodsOrderTask.GOODS_ORDER_UNRECEIVE);
        fragmentList.add(typeUnrecived);
        GoodsOrderFragment typeComplete = new GoodsOrderFragment();
        typeComplete.setOrderType(GoodsOrderTask.GOODS_ORDER_COMPLETE);
        fragmentList.add(typeComplete);
        GoodsOrderFragment typeBack = new GoodsOrderFragment();
        typeBack.setOrderType(GoodsOrderTask.GOODS_ORDER_BACK);
        fragmentList.add(typeBack);

        GoodsOrderFragmentAdapter fragmentAdapter = new GoodsOrderFragmentAdapter(getSupportFragmentManager(), fragmentList, Arrays.asList(tab));
        viewPager.setAdapter(fragmentAdapter);
        viewPager.setOffscreenPageLimit(tab.length);
        indicator.setupWithViewPager(viewPager);
    }

}
